﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;

namespace SurehealthForms.Manager
{
    public partial class DoctorSpending : Form
    {
        List<Doctor> doctorList = new List<Doctor>();

        public DoctorSpending()
        {           
            InitializeComponent();
        }

        void DoctorList()
        {
            try
            {
                StreamReader reader = new StreamReader("DoctorList.txt");

                while (reader.EndOfStream == false)
                {
                    string DoctorName;
                    DoctorName = reader.ReadLine();
                    XmlDocument xmlDoc = null;
                    xmlDoc = new XmlDocument();
                    xmlDoc.Load(DoctorName + ".Xml");

                    System.Xml.XmlElement root = xmlDoc.DocumentElement;
                    Console.WriteLine(root.Name);
                    DoctorName = root.GetAttribute("Name");
                    Console.WriteLine(DoctorName);

                    XmlNode Node = root["Spendature"];
                    decimal Spendature = Convert.ToDecimal(Node.FirstChild.Value);

                    doctorList.Add(new Doctor(DoctorName.ToString(), DoctorName + "patients.txt", Spendature));

                    xmlDoc.Save(DoctorName + ".Xml");
                }
            }
            catch
            {
                MessageBox.Show("There is no registered doctors as of yet");
            }
        }

        List<string> _items = new List<string>();
        List<string> _itemsSpend = new List<string>();

        void printDoctorList()
        {
            foreach (Doctor D in doctorList)
            {
                _items.Add(D.DoctorName.ToString());
                _itemsSpend.Add(D.MonthlySpendature.ToString());
            }
            ListBox1.DataSource = _items;
            listBox2.DataSource = _itemsSpend;
            ListBox1.Update();
            listBox2.Update();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DoctorList();
            printDoctorList();
        }

        private void DoctorSpending_Load(object sender, EventArgs e)
        {
            DoctorList();
            printDoctorList();
        }


    }
}
